package com.zzyl.generator.util;

import com.zzyl.common.constant.Constants;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class testVelocity {

    public static void main(String[] args) throws IOException {

        Properties p =new Properties();

        p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);

        Velocity.init(p);

        VelocityContext context=new VelocityContext();

        context.put("message","加油朋友");

        Template template =Velocity.getTemplate("vm/a.html.vm","UTF-8");

        FileWriter fileWriter = new FileWriter("/Users/xulei/Desktop");
        //合并模板和数据模型
        template.merge(context,fileWriter);
        //关闭流
        fileWriter.close();
    }
}
